/*
  The MIT License
  
  Copyright (c) 2009 smath project
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/
package pl.smath.expression.serializer;

import pl.smath.expression.model.ConjunctionTerm;
import pl.smath.expression.model.DisjunctionTerm;
import pl.smath.expression.model.ExponentiationTerm;
import pl.smath.expression.model.FractionTerm;
import pl.smath.expression.model.InTerm;
import pl.smath.expression.model.NumberSetTerm;
import pl.smath.expression.model.ProductTerm;
import pl.smath.expression.model.RelationTerm;
import pl.smath.expression.model.RootTerm;
import pl.smath.expression.model.SetSumTerm;
import pl.smath.expression.model.SetTerm;
import pl.smath.expression.model.SumTerm;
import pl.smath.expression.model.Term;

abstract class AbstractSerializer {

	public String serialize(Term term){
     
		if(term instanceof RelationTerm){
			return process((RelationTerm)term);
		}
		else if(term instanceof SumTerm){
			return process((SumTerm)term);
		}
		else if(term instanceof SetSumTerm){
			return process((SetSumTerm)term);
		}
		else if(term instanceof ProductTerm){
			return process((ProductTerm)term);
		}
		else if(term instanceof FractionTerm){
			return process((FractionTerm)term);
		}
		else if(term instanceof ExponentiationTerm){
			if(term instanceof RootTerm){
				return process((RootTerm)term);
			}
			else{
				return process((ExponentiationTerm)term);
			}
		}
		else if(term instanceof DisjunctionTerm){
			return process((DisjunctionTerm)term);
		}
		else if(term instanceof ConjunctionTerm){
			return process((ConjunctionTerm)term);
		}
		else if(term instanceof SetTerm){
			return process((SetTerm)term);
		}
		else if(term instanceof NumberSetTerm){
			return process((NumberSetTerm)term);
		}
		else if(term instanceof InTerm){
			return process((InTerm)term);
		}
		else{
			return process(term);
		}
		 
	}
	 

	protected abstract String process(InTerm term);
	protected abstract String process(RelationTerm term);
	protected abstract String process(NumberSetTerm term);
	protected abstract String process(ExponentiationTerm expTerm);
	protected abstract String process(FractionTerm fracTerm);
	protected abstract String process(SetTerm inputTerm);
	protected abstract String process(SetSumTerm inputTerm);
	protected abstract String process(SumTerm inputTerm);
	protected abstract String process(DisjunctionTerm inputTerm);
	protected abstract String process(ConjunctionTerm inputTerm);
	protected abstract String process(ProductTerm productTerm);
	protected abstract String process(RootTerm term);
	protected abstract String process(Term term);
	
}       
